cmake_minimum_required(VERSION 3.5)

project(ai-chat-client LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

# 启用 C++17 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# They need to be set before the find_package(Qt5 ...) call.

#if(ANDROID)
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
#    if (ANDROID_ABI STREQUAL "armeabi-v7a")
#        set(ANDROID_EXTRA_LIBS
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
#    endif()
#endif()

find_package(Qt5 COMPONENTS Widgets REQUIRED)
# 查找 nlohmann_json 库
find_package(nlohmann_json REQUIRED)

find_package(PkgConfig REQUIRED)

pkg_check_modules(GIO REQUIRED gio-unix-2.0)
pkg_check_modules(KYAINLP REQUIRED kysdk-genai-nlp)
pkg_check_modules(KYSDK_AI_VISION kysdk-coreai-vision)
pkg_check_modules(KYAISPEECH kysdk-coreai-speech) #语音

# 向量化
pkg_check_modules(Embedding REQUIRED IMPORTED_TARGET kysdk-coreai-embedding)


include_directories(
    src
    src/historybasedsession
    src/ordinarysession
    src/historymanager
    src/texttopcm
    src/structs
    src/tools
    
    src/qt
    src/bridge
    src/historybridge
    
    
    src/listenandspeak
    src/pcmtotext
    src/speechreceiveandoutput

    src/ragsearch
    
    ${KYSDK_AI_VISION_INCLUDE_DIRS}
    ${KYAINLP_INCLUDE_DIRS}
    ${GLIB_INCLUDE_DIRS}
    ${GIO_INCLUDE_DIRS}
    ${KYAISPEECH_INCLUDE_DIRS} #语音
)

if(ANDROID)
  add_library(ai-chat-client SHARED
    src/main.cpp
    src/qt/ChatWindow.cpp
    src/qt/ChatWorker.cpp
  )
else()
  add_executable(ai-chat-client
    src/ordinarysession/Ordinary.cpp
    src/historybasedsession/HistoryBased.cpp
    src/historymanager/HistoryManager.cpp
    src/texttopcm/TextToPcm.cpp
    src/pcmtotext/PcmToText.cpp
    src/speechreceiveandoutput/OutputAndReceive.cpp
    src/listenandspeak/ListenAndSpeak.cpp

    src/qt/ChatWindow.cpp
    src/qt/ChatWorker.cpp
    src/qt/HistoryWorker.cpp

    src/bridge/ModelBridge.cpp
    src/historybridge/HistoryBridge.cpp

    src/qt/VoiceWorker.cpp
    src/qt/VoiceSpeakWorker.cpp

    src/qt/ConfigDialog.cpp
    
    src/tools/Tools.cpp
   
    src/ragsearch/EmbedText.cpp
    src/ragsearch/RAGSearch.cpp
    
    src/main.cpp
  )
endif()

target_link_libraries(ai-chat-client

    pthread
    ${KYSDK_AI_VISION_LIBRARIES}
    ${GLIB_LIBRARIES}
    ${GIO_LIBRARIES}
    ${KYAINLP_LIBRARIES}
    ${KYAISPEECH_LIBRARIES} #语音
    PkgConfig::Embedding
    nlohmann_json::nlohmann_json
    Qt5::Widgets
)
